﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcLibrary.Repository;
using System.IO;

namespace WebVideo.Areas.Admin.Controllers
{
    public class LoginController : Controller
    {
        //
        // GET: /Admin/Login/

        public ActionResult Index()
        {
            return View();
        }
        public JsonResult CheckId(string username, string pass)
        {
            EntityAdmin user = new EntityAdmin();
            
            user.UserName = " ";
            try
            {
                dbVideoDataContext db = new dbVideoDataContext();
                Security ser = new Security();
                string passHex = ser.GetHashPassword(pass);

                //EntityAdmin Admin1 = new EntityAdmin();
                //string passHexTest = ser.GetHashPassword("123456");
                //Admin1.UserName = "BoCau";
                //Admin1.Pass = passHexTest;
                //db.EntityAdmins.InsertOnSubmit(Admin1);
                //db.SubmitChanges();

                var adminquery = (from p in db.EntityAdmins
                                  where p.UserName == username && p.Pass == passHex
                                  select p).Single();


                if (adminquery != null)
                {
                    user = adminquery;
                    Session["AdminId"] = user.UserName; // tao session


                }
                return Json(user);
            }
            catch
            {
                return Json(user);
            }
        }
        public ActionResult logout()
        {       
            Session["AdminId"] = null; // Xoa session       
            return RedirectToAction("Index", "Index", new { area = "" });
        }

    }
}
